package com.spider.admin.store.primary.model;


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.spider.admin.conf.validator.UniqueValue;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;

@Getter
@Setter
@Validated
@Entity
@Table(name = "t_service_marks")

@Accessors(chain = true)

@Data
@EqualsAndHashCode(callSuper = true)
public class ServiceInfo extends SuperVO {
    @Id
    @Column(name = "pid")
    private String pid;

    @NotEmpty(message = "服务名称不能为空", groups = Save.class)
    @UniqueValue(domainClass = ServiceInfo.class, fieldName = "serviceName", message = "服务名称不能重复发布", groups = {Save.class})
    @Column(name = "service_name")
    private String serviceName;

    @Column(name = "service_desc")
    private String serviceDesc;

    @NotEmpty(message = "应用ID不能为空", groups = Save.class)
    @Column(name = "app_id")
    private String appId;

    @Transient
    @JsonIgnore
    private AppInfo appInfo;

    @Transient
    private String appName;

    public String getAppName() {
        return appInfo == null ? null : appInfo.getAppName();
    }


    @Column(name = "service_url")
    private String serviceUrl;

    @Transient
    @NotEmpty(message = "服务URI不能为空", groups = Save.class)
    private String serviceUri;

    public String getServiceUri() {
        if (appInfo == null) {
            return this.serviceUri;
        }
        return StringUtils.isEmpty(this.serviceUrl) ? null : this.serviceUrl.replace(appInfo.getAppUri(), "");
    }


    @Column(name = "publish_client_id")
    private String publishClientId;


    @Column(name = "service_doc_id")
    private String serviceDocId;

    @NotEmpty(message = "服务发布租户不能为空", groups = Save.class)
    @Column(name = "tenant_id")
    private String tenantId;

    @Column(name = "line_status")
    private String lineStatus;

    @Transient
    private String vpid;

    @Transient
    private boolean subject=false;

    public boolean isSubject(){
        if(StringUtils.isNotEmpty(getVpid())){
            return true;
        }else{
            return false;
        }
    }
}

